package day18;

import java.util.Random;
import java.util.concurrent.locks.ReentrantLock;

public class Lottery {
    int arr[]={10,5,20,50,100,200,500,800,2,80,300};
    Random rd=new Random();
    ReentrantLock lock=new ReentrantLock(true);
    public void lottery() {
        String name=Thread.currentThread().getName();
        for (int i=0;i<arr.length;i++){
            lock.lock();
            try {
                Thread.sleep(1000);
                int n=rd.nextInt(arr.length);
                System.out.println(name+"又产生了一个"+arr[n]+"元大奖");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }finally {
                lock.unlock();
            }
        }
    }
    public static void main(String[] args) {
        Lottery lt=new Lottery();
        new Thread(()->{
            lt.lottery();
        },"抽奖箱1").start();
        new Thread(()->{
            lt.lottery();
        },"抽奖箱2").start();
    }
}
